package com.ycsj.goldmedalnewconcept.fragment;

import java.util.ArrayList;
import java.util.List;
import com.ycsj.goldmedalnewconcept.MainActivity;
import com.ycsj.goldmedalnewconcept.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

//教学计划
public class TeachingProgramFragment extends Fragment {
	
	private Activity ctx;
	private View layout;
	private MainActivity parentActivity;	
	private ListView lv_huodng;
	private List list = new ArrayList<Object>();
	private MyAdapter mAdapter;
	
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		if (layout == null) {
			ctx = this.getActivity();
			parentActivity = (MainActivity) getActivity();
			layout = ctx.getLayoutInflater().inflate(R.layout.fragment_teachingprogram,
					null);
			initView(layout);
            
			list.add("1");
			list.add("2");
			
			
			mAdapter = new MyAdapter(getActivity());
			lv_huodng.setAdapter(mAdapter);
			
		} else {
			ViewGroup parent = (ViewGroup) layout.getParent();
			if (parent != null) {
				parent.removeView(layout);
			}
		}
		return layout;
	}
	
	private void initView(View view) {
		// TODO Auto-generated method stub
		lv_huodng = (ListView) view.findViewById(R.id.lv_huodong);
	}
	
	class ViewHolder {
	}

	class MyAdapter extends BaseAdapter {

		private LayoutInflater mInflater = null;

		private MyAdapter(Context context) {
			this.mInflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = mInflater.inflate(R.layout.teachingprogram_list_item, null);
				// holder.img = (ImageView)item.findViewById(R.id.img)
				// holder.title = (TextView)item.findViewById(R.id.title);
				// holder.info = (TextView)item.findViewById(R.id.info);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			// holder.img.setImageResource(R.drawable.ic_launcher);
			// holder.title.setText("Hello");
			// holder.info.setText("World");
			return convertView;
		}
	}
}
